<?php 


/** 
***************************************************
*欢迎使用免费版xSite企业自助建站软件！
*这是一个专业为搜索引擎营销而设计的，极稳定、极易维护的建站软件！
*官方客服：help@php.net.cn
*官方下载网址：http://www.php.net.cn/xsite/ 
***************************************************
**/




 function tpl_product_list ($args = null) { global $site_id, $setting, $system_category; if (!empty($args)) { parse_str($args); } $category = empty($category) ? '' : strip_tags($category); $status = empty($status) ? 0 : intval($status); $ptitle = empty($ptitle) ? 0 : 1; $page = empty($page) ? 1 : intval($page); $limit = empty($limit) ? 20 : intval($limit); $sort = (isset($sort) && strtoupper($sort) == 'DESC') ? 'DESC' : 'ASC'; $offset = ($page - 1) * $limit; $depth = empty($depth) ? 0 : intval($depth); if (!isset($GLOBALS['db'])) { $db = new db_mysql(); } else { $db = &$GLOBALS['db']; } $sql = "SELECT COUNT(*) AS num FROM  `{$site_id}_product` AS p WHERE p.`key` > 0"; $where = ''; if (!empty($category)) { if ($depth > 0) { $category_list = cat_child_category($category, $system_category); $category_list = array_keys($category_list); $category = implode("','" , $category_list); $where .= " AND p.`category` in ('{$category}') "; } else { $where .= " AND p.`category` = '{$category}' "; } } if (!empty($status)) { $where .= " AND p.`status` = '{$status}' "; } if (!empty($ptitle)) { $where .= " AND p.`ptitle` != '' "; } $sql .= " {$where} "; $db->query($sql); $row = $db->fetchRow(); $row = $row['num']; $multipage = db_multipage($row, $page, $limit); $sql = "SELECT p.* FROM  `{$site_id}_product` AS p WHERE p.`key` > 0"; $sql .= " {$where} "; $sql .= " ORDER BY p.`key` DESC "; $sql .= " LIMIT {$multipage['start_row']}, {$multipage['limit']} "; $db->query($sql); $temp = $db->fetchAll(); $product_list = array(); if (is_array($temp) && count($temp)) { foreach ($temp as $row) { $row['html_link'] = (SITE_REWRITE ? SITE_PATH . "/" : SITE_PATH . "/?" ) . "{$system_category[$row['category']]['detailed_tpl']}/{$row['category']}/{$row['key']}.html"; $product_list[$row['key']] = $row; } } @format_data($product_list); return array('page' => $multipage, 'list' => $product_list); } function tpl_product_search($args) { global $site_id, $setting, $system_category; if (!empty($args)) { parse_str($args); } $category = empty($category) ? '' : strip_tags($category); $page = empty($page) ? 1 : intval($page); $limit = empty($limit) ? 20 : intval($limit); $offset = ($page - 1) * $limit; $depth = empty($depth) ? 0 : intval($depth); $keywords = empty($keywords) ? '' : strip_tags($keywords); if (!isset($GLOBALS['db'])) { $db = new db_mysql(); } else { $db = &$GLOBALS['db']; } $sql = "SELECT COUNT(*) AS num FROM  `{$site_id}_product` AS p WHERE p.`key` > 0"; $where = ''; if (!empty($category)) { if ($depth > 0) { $category_list = cat_child_category($category, $system_category); $category_list = array_keys($category_list); $category = implode("','" , $category_list); $where .= " AND p.`category` in ('{$category}') "; } else { $where .= " AND p.`category` = '{$category}' "; } } if (!empty($keywords)) { $where .= " AND p.`name` LIKE '%{$keywords}%' "; } $sql .= " {$where} "; $db->query($sql); $row = $db->fetchRow(); $row = $row['num']; $multipage = db_multipage($row, $page, $limit); $sql = "SELECT p.* FROM  `{$site_id}_product` AS p WHERE p.`key` > 0"; $sql .= " {$where} "; $sql .= " ORDER BY p.`key` DESC "; $sql .= " LIMIT {$multipage['start_row']}, {$multipage['limit']} "; $db->query($sql); $temp = $db->fetchAll(); $product_list = array(); if (is_array($temp) && count($temp)) { foreach ($temp as $row) { $row['html_link'] = (SITE_REWRITE ? SITE_PATH . "/" : SITE_PATH . "/?" ) . "{$system_category[$row['category']]['detailed_tpl']}/{$row['category']}/{$row['key']}.html"; $product_list[$row['key']] = $row; } } @format_data($product_list); return array('page' => $multipage, 'list' => $product_list); } function tpl_product_details($args) { global $site_id, $site_url; if (!empty($args)) { parse_str($args); } if (empty($key) || empty($category)) { return array(); } else { $key = intval($key); } $category = empty($category) ? '' : strip_tags($category); if (empty($category)) { return array(); } $product_info = read_array_file(SITE_ROOT . "/data/setting/{$site_url}/{$category}/{$key}.txt"); return $product_info; } function tpl_article_list ($args = null) { global $site_id, $setting, $system_category; if (!empty($args)) { parse_str($args); } $category = empty($category) ? '' : strip_tags($category); $status = empty($status) ? 0 : intval($status); $is_first = empty($is_first) ? 0 : intval($is_first); $ptitle = empty($ptitle) ? 0 : 1; $page = empty($page) ? 1 : intval($page); $limit = empty($limit) ? 20 : intval($limit); $sort = (isset($sort) && strtoupper($sort) == 'DESC') ? 'DESC' : 'ASC'; $offset = ($page - 1) * $limit; $depth = empty($depth) ? 0 : intval($depth); if (!isset($GLOBALS['db'])) { $db = new db_mysql(); } else { $db = &$GLOBALS['db']; } $sql = "SELECT COUNT(*) AS num FROM  `{$site_id}_article` AS a WHERE a.`key` > 0"; $where = ''; if (!empty($category)) { if ($depth > 0) { $category_list = cat_child_category($category, $system_category); $category_list = array_keys($category_list); $category = implode("','" , $category_list); $where .= " AND a.`category` in ('{$category}') "; } else { $where .= " AND a.`category` = '{$category}' "; } } if (!empty($status)) { $where .= " AND a.`status` = '{$status}' "; } if (!empty($ptitle)) { $where .= " AND a.`ptitle` != '' "; } if (!empty($is_first)) { $where .= " AND a.`is_first` == '{$is_first}' "; } $sql .= " {$where} "; $db->query($sql); $row = $db->fetchRow(); $row = $row['num']; $multipage = db_multipage($row, $page, $limit); $sql = "SELECT a.* FROM  `{$site_id}_article` AS a WHERE a.`key` > 0"; $sql .= " {$where} "; $sql .= " ORDER BY a.`key` DESC "; $sql .= " LIMIT {$multipage['start_row']}, {$multipage['limit']} "; $db->query($sql); $temp = $db->fetchAll(); $article_list = array(); if (is_array($temp) && count($temp)) { foreach ($temp as $row) { $row['html_link'] = (SITE_REWRITE ? SITE_PATH . "/" : SITE_PATH . "/?" ) . "{$system_category[$row['category']]['detailed_tpl']}/{$row['category']}/{$row['key']}.html"; $article_list[$row['key']] = $row; } } @format_data($article_list); return array('page' => $multipage, 'list' => $article_list); } function tpl_article_search($args) { global $site_id, $setting, $system_category; if (!empty($args)) { parse_str($args); } $category = empty($category) ? '' : strip_tags($category); $page = empty($page) ? 1 : intval($page); $limit = empty($limit) ? 20 : intval($limit); $offset = ($page - 1) * $limit; $depth = empty($depth) ? 0 : intval($depth); $keywords = empty($keywords) ? '' : strip_tags($keywords); if (!isset($GLOBALS['db'])) { $db = new db_mysql(); } else { $db = &$GLOBALS['db']; } $sql = "SELECT COUNT(*) AS num FROM  `{$site_id}_article` AS a WHERE a.`key` > 0"; $where = ''; if (!empty($category)) { if ($depth > 0) { $category_list = cat_child_category($category, $system_category); $category_list = array_keys($category_list); $category = implode("','" , $category_list); $where .= " AND a.`category` in ('{$category}') "; } else { $where .= " AND a.`category` = '{$category}' "; } } if (!empty($keywords)) { $where .= " AND a.`body_name` LIKE '%{$keywords}%' "; } $sql .= " {$where} "; $db->query($sql); $row = $db->fetchRow(); $row = $row['num']; $multipage = db_multipage($row, $page, $limit); $sql = "SELECT a.* FROM  `{$site_id}_article` AS a WHERE a.`key` > 0"; $sql .= " {$where} "; $sql .= " ORDER BY a.`key` DESC "; $sql .= " LIMIT {$multipage['start_row']}, {$multipage['limit']} "; $db->query($sql); $temp = $db->fetchAll(); $article_list = array(); if (is_array($temp) && count($temp)) { foreach ($temp as $row) { $row['html_link'] = (SITE_REWRITE ? SITE_PATH . "/" : SITE_PATH . "/?" ) . "{$system_category[$row['category']]['detailed_tpl']}/{$row['category']}/{$row['key']}.html"; $article_list[$row['key']] = $row; } } @format_data($article_list); return array('page' => $multipage, 'list' => $article_list); } function tpl_article_details($args) { global $site_id, $site_url; if (!empty($args)) { parse_str($args); } if (empty($key) || empty($category)) { return array(); } else { $key = intval($key); } $category = empty($category) ? '' : strip_tags($category); if (empty($category)) { return array(); } $article_info = read_array_file(SITE_ROOT . "/data/setting/{$site_url}/{$category}/{$key}.txt"); return $article_info; } function tpl_article_default_page ($category) { global $site_id, $site_url; if (!isset($GLOBALS['db'])) { $db = new db_mysql(); } else { $db = &$GLOBALS['db']; } if (empty($category)) { return false; } $sql = "SELECT a.* FROM  `{$site_id}_article` AS a WHERE a.`category` = '{$category}' AND a.`is_first` = 8 "; $db->query($sql); $list = $db->fetchAll(); if (is_array($list) && count($list) > 0) { $temp = array_shift($list); return $temp['key']; } else { return ''; } } function tpl_page_details ($category) { global $site_id, $site_url; if (empty($category)) { return array(); } $page_info_file = SITE_ROOT . "/data/setting/{$site_url}/{$category}/index.txt"; if (file_exists($page_info_file)) { $page_info = read_array_file($page_info_file); return $page_info; } else { return array(); } } function tpl_category_id($category = '', $module = '') { global $system_category; if (empty($category)) { $temp = array(); foreach ($system_category as $k => $v) { if (in_array($module, array('article', 'product', 'page'))) { if ($v['module'] == $module) { $temp[] = $k; } } } $catid = $temp[array_rand($temp)]; return $catid; } else { if (in_array($module, array('article', 'product', 'page'))) { if (isset($system_category[$category]) && $system_category[$category]['module'] == $module) { return $category; } else { $temp = array(); foreach ($system_category as $k => $v) { if ($v['module'] == $module) { $temp[] = $k; } } $catid = $temp[array_rand($temp)]; return $catid; } } else { return $category; } } } function tpl_block_html($key) { global $site_url,$skinid; $block_file = SITE_ROOT . "/data/setting/{$site_url}/block/{$skinid}/{$key}.txt"; if ($html_code = @file_get_contents($block_file)) { return $html_code; } else { return ''; } } function _e($var1, $var2 = FALSE, $var3 = FALSE) { if (!isset($var1) || empty($var1) || $var1 == '') { if (!isset($var2) || empty($var2) || $var2 == '') { if (!isset($var3) || empty($var3) || $var3 == '') { return ''; } else { return $var3; } } else { return $var2; } } else { return $var1; } } function tpl_media_pay($div, $media_file, $width, $height, $autoplay = 1, $default_images = '', $args = array()) { global $site_path; $html = <<<EOD
<script language="javascript" type="text/javascript">if (typeof jwplayer=='undefined'){document.write('\<script type="text/javascript" src="{$site_path}/templates/default/siteteam.player.js"\>\</script\>');}</script>
<div id="{$div}" style="width:{$width}px; height:{$height}px; margin:0px; padding:0px"></div>
<script type="text/javascript">
jwplayer("{$div}").setup({
	file: "{$media_file}",
	flashplayer: "{$site_path}/templates/default/player.swf",
	image: "{$default_images}",
	width: {$width},
	height: {$height}
});

</script>
EOD;
if ($autoplay) { $html .= <<<EOD
<script language="javascript" type="text/javascript">jwplayer("{$div}").play();</script>
EOD;
} return $html; } function seo($moudle = 'index', &$data = array()) { extract($GLOBALS['setting']); $seo_title = (!empty($seo_title)) ? $seo_title : $GLOBALS['site_title']; $seo_keywords = (!empty($seo_keywords)) ? $seo_keywords : $GLOBALS['site_keywords']; $seo_description = (!empty($seo_description)) ? $seo_description : $GLOBALS['site_description']; if (isset($GLOBALS['category']) && !empty($GLOBALS['category'])) { $category = $GLOBALS['category']; } else { $category = null; } if ($moudle == 'index') { } if ($moudle == 'product_list') { if (!empty($category) && array_key_exists($category, $GLOBALS['product_category'])) { if (array_key_exists('seo_title', $GLOBALS['product_category'][$category]) && !empty($GLOBALS['product_category'][$category]['seo_title'])) { $seo_title = $GLOBALS['product_category'][$category]['seo_title']; } if (array_key_exists('seo_keywords', $GLOBALS['product_category'][$category]) && !empty($GLOBALS['product_category'][$category]['seo_keywords'])) { $seo_keywords = $GLOBALS['product_category'][$category]['seo_keywords']; } if (array_key_exists('seo_description', $GLOBALS['product_category'][$category]) && !empty($GLOBALS['product_category'][$category]['seo_description'])) { $seo_description = $GLOBALS['product_category'][$category]['seo_description']; } } } if ($moudle == 'product') { if (!empty($category) && array_key_exists($category, $GLOBALS['product_category'])) { if (is_array($data) && array_key_exists('seo_title', $data) && !empty($data['seo_title'])) { $seo_title = $data['seo_title']; } else { if (array_key_exists('seo_title', $GLOBALS['product_category'][$category]) && !empty($GLOBALS['product_category'][$category]['seo_title'])) { $seo_title = $GLOBALS['product_category'][$category]['seo_title']; } } if (is_array($data) && array_key_exists('seo_keywords', $data) && !empty($data['seo_keywords'])) { $seo_keywords = $data['seo_keywords']; } else { if (array_key_exists('seo_keywords', $GLOBALS['product_category'][$category]) && !empty($GLOBALS['product_category'][$category]['seo_keywords'])) { $seo_keywords = $GLOBALS['product_category'][$category]['seo_keywords']; } } if (is_array($data) && array_key_exists('seo_description', $data) && !empty($data['seo_description'])) { $seo_description = $data['seo_description']; } else { if (array_key_exists('seo_description', $GLOBALS['product_category'][$category]) && !empty($GLOBALS['product_category'][$category]['seo_description'])) { $seo_description = $GLOBALS['product_category'][$category]['seo_description']; } } } } if ($moudle == 'article_list') { if (!empty($category) && array_key_exists($category, $GLOBALS['article_category'])) { if (array_key_exists('seo_title', $GLOBALS['article_category'][$category]) && !empty($GLOBALS['article_category'][$category]['seo_title'])) { $seo_title = $GLOBALS['article_category'][$category]['seo_title']; } if (array_key_exists('seo_keywords', $GLOBALS['article_category'][$category]) && !empty($GLOBALS['article_category'][$category]['seo_keywords'])) { $seo_keywords = $GLOBALS['article_category'][$category]['seo_keywords']; } if (array_key_exists('seo_description', $GLOBALS['article_category'][$category]) && !empty($GLOBALS['article_category'][$category]['seo_description'])) { $seo_description = $GLOBALS['article_category'][$category]['seo_description']; } } } if ($moudle == 'article') { if (!empty($category) && array_key_exists($category, $GLOBALS['article_category'])) { if (is_array($data) && array_key_exists('seo_title', $data) && !empty($data['seo_title'])) { $seo_title = $data['seo_title']; } else { if (is_array($data) && array_key_exists('body_name', $data) && !empty($data['body_name'])) { $seo_title = $data['body_name']; } else { if (array_key_exists('seo_title', $GLOBALS['article_category'][$category]) && !empty($GLOBALS['article_category'][$category]['seo_title'])) { $seo_title = $GLOBALS['article_category'][$category]['seo_title']; } } } if (is_array($data) && array_key_exists('seo_keywords', $data) && !empty($data['seo_keywords'])) { $seo_keywords = $data['seo_keywords']; } else { if (array_key_exists('seo_keywords', $GLOBALS['article_category'][$category]) && !empty($GLOBALS['article_category'][$category]['seo_keywords'])) { $seo_keywords = $GLOBALS['article_category'][$category]['seo_keywords']; } } if (is_array($data) && array_key_exists('seo_description', $data) && !empty($data['seo_description'])) { $seo_description = $data['seo_description']; } else { if (array_key_exists('seo_description', $GLOBALS['article_category'][$category]) && !empty($GLOBALS['article_category'][$category]['seo_description'])) { $seo_description = $GLOBALS['article_category'][$category]['seo_description']; } } } } $GLOBALS['seo_title'] = $seo_title; $GLOBALS['seo_keywords'] = $seo_keywords; $GLOBALS['seo_description'] = $seo_description; } function format_data(&$array) { if (!is_array($array)) { return false; } foreach ($array as $k => $v) { if (is_array($array[$k])) { format_data($array[$k]); } else { $array[$k] = htmlspecialchars($array[$k]); } } } function theme_is_standard($skinid) { $tpldir = SITE_DIR . "/templates/{$skinid}"; if (!file_exists($tpldir)) { return false; } if (!file_exists("{$tpldir}/info.txt")) { return false; } $info = read_ini_txt("{$tpldir}/info.txt"); $var = array('name', 'ahutor', 'demo', 'thumbnail', 'article_main_tpl', 'article_list_tpl', 'article_detailed_tpl', 'product_main_tpl', 'product_list_tpl', 'product_detailed_tpl', 'page_detailed'); foreach ($var as $v) { if (!array_key_exists($v, $info)) { return false; } } return true; } function theme_info ($skinid) { $tpldir = SITE_DIR . "/templates/{$skinid}"; if (!file_exists("{$tpldir}/info.txt")) { return false; } $info = read_ini_txt("{$tpldir}/info.txt"); $info['skinid'] = $skinid; return $info; } function theme_list() { if (file_exists(SITE_ROOT . '/data/cache/tplconfig.php')) { include SITE_ROOT . '/data/cache/tplconfig.php'; return $theme_list; } else { return theme_cache(); } } function theme_cache() { $themedir = read_dir(SITE_DIR . '/templates'); $theme_list = array(); if (is_array($themedir['dir']) && count($themedir['dir'])) { foreach ($themedir['dir'] as $k => $v) { if (theme_is_standard($v)) { $theme_list[$v] = theme_info($v); } } } save_array_to_file($theme_list, SITE_ROOT . '/data/cache/tplconfig.php', 'theme_list'); return $theme_list; } ?>